﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace jnpic.Web.userinfo
{
    /// <summary>
    /// GetUser 的摘要说明
    /// </summary>
    public class GetUser : IHttpHandler, IRequiresSessionState
    {
        jnpic.BLL.userinfo bll = new jnpic.BLL.userinfo();

        public void ProcessRequest(HttpContext context)
        {

            string ac = "";
            if (null != context.Request.Form["action"])
            {//获取前台传来的值  
                ac = context.Request.Form["action"].ToString().Trim();
            }
            else if (null != context.Request.QueryString["action"])
            {
                ac = context.Request.QueryString["action"].ToString().Trim();
            }

            if (ac == "query")
                Query(context);
            else if (ac == "add")
                add(context);
            else if (ac == "adda")
                adda(context);
            else if (ac == "modify")
                modify(context);
            else if (ac == "modifya")
                modifya(context);
            else if (ac == "delete")
                delete(context);
            else if (ac == "querymy")
                Querymy(context);
            else if (ac == "querya")
                Querya(context);
            else if (ac == "myinfo")
                myinfo(context);
            else if (ac == "updatemyinfo")
                updatemyinfo(context);
            else if (ac == "querymym")
                Querymym(context);            
            else if (ac == "chpwd")
                updatepass(context);

        }
        public void updatepass(HttpContext context)
        {
            if (Web.Admin.myinfo.isLogin(context))
            {
                context.Response.ContentType = "text/plain";
                int uid = Web.Admin.myinfo.getID(context);
                string OldPassword = context.Request["OldPassword"];
                string NewPassword = context.Request["NewPassword"];                
                jnpic.BLL.userinfo bll = new jnpic.BLL.userinfo();
                if (bll.Updatepass(uid, OldPassword, NewPassword))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();

                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
       
        public void modifya(HttpContext context)
        {
            if (Web.Admin.myinfo.isLogin(context))
            {
                context.Response.ContentType = "text/plain";
                string uname = context.Request.Form["uname"];
                string upwd = context.Request.Form["upwd"];
                string utruename = context.Request.Form["utruename"];
                string uphone = context.Request.Form["uphone"];
                string uemail = context.Request.Form["uemail"];
                string uunit = context.Request.Form["uunit"];
                string utel = context.Request.Form["utel"];
                string uprovince = context.Request.Form["uprovince"];
                string ucity = context.Request.Form["ucity"];
                string ucounty = context.Request.Form["ucounty"];
                string uadd = context.Request.Form["uadd"];
                int ulevel = int.Parse(context.Request.Form["ulevel"]);
                string utype = context.Request.Form["utype"];
                string remark = context.Request.Form["remark"];
                int uid = 0;
                string uidstr = context.Request.Form["uid"];
                if (uidstr != "")
                    uid = int.Parse(uidstr);
                jnpic.Model.userinfo model = new jnpic.Model.userinfo();
                model.uname = uname;
                model.upwd = upwd;
                model.utruename = utruename;
                model.uphone = uphone;
                model.uemail = uemail;
                model.uunit = uunit;
                model.utel = utel;
                model.uprovince = uprovince;
                model.ucity = ucity;
                model.ucounty = ucounty;
                model.uadd = uadd;
                model.ulevel = ulevel;
                model.utype = utype;
                model.remark = remark;
                model.uid = uid;
                jnpic.BLL.userinfo bll = new jnpic.BLL.userinfo();
                if (bll.Updatea(model))
                {
                    jnpic.BLL.SysUserRole sur = new BLL.SysUserRole();
                    jnpic.Model.SysUserRole rr = new Model.SysUserRole();
                    rr.UserID = uid;
                    rr.RoleID = 6 - ulevel;
                    sur.Add(rr);
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();

                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void delete(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = 0;
                string uidstr = context.Request.QueryString["uid"];
                if (uidstr != "")
                    uid = int.Parse(uidstr);

                jnpic.BLL.userinfo bll = new jnpic.BLL.userinfo();
                if (bll.Delete(uid))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();

                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void updatemyinfo(HttpContext context)
        {
            if (Web.Admin.myinfo.isLogin(context))
            {
                context.Response.ContentType = "text/plain";
                int uid = Web.Admin.myinfo.getID(context);                
                string utruename = context.Request.Form["utruename"];
                string uphone = context.Request.Form["uphone"];
                string uemail = context.Request.Form["uemail"];               
                string utel = context.Request.Form["utel"];                
                string uadd = context.Request.Form["uadd"];                
                jnpic.Model.userinfo model = new jnpic.Model.userinfo();
               
                model.utruename = utruename;
                model.uphone = uphone;
                model.uemail = uemail;                
                model.utel = utel;                
                model.uadd = uadd;               
                
                model.uid = uid;
                jnpic.BLL.userinfo bll = new jnpic.BLL.userinfo();
                if (bll.Updatemyinfo(model))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();

                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void modify(HttpContext context)
        {
            if (Web.Admin.myinfo.isLogin(context))
            {
                context.Response.ContentType = "text/plain";
                string uname = context.Request.Form["uname"];
                string upwd = context.Request.Form["upwd"];
                string utruename = context.Request.Form["utruename"];
                string uphone = context.Request.Form["uphone"];
                string uemail = context.Request.Form["uemail"];
                string uunit = context.Request.Form["uunit"];
                string utel = context.Request.Form["utel"];
                string uprovince = context.Request.Form["uprovince"];
                string ucity = context.Request.Form["ucity"];
                string ucounty = context.Request.Form["ucounty"];
                string uadd = context.Request.Form["uadd"];
                //int ulevel = int.Parse(context.Request.Form["level"]);
                string utype = context.Request.Form["utype"];
                string remark = context.Request.Form["remark"];
                int uid = 0;
                string uidstr = context.Request.Form["uid"];
                if (uidstr != "")
                    uid = int.Parse(uidstr);
                jnpic.Model.userinfo model = new jnpic.Model.userinfo();
                model.uname = uname;
                model.upwd = upwd;
                model.utruename = utruename;
                model.uphone = uphone;
                model.uemail = uemail;
                model.uunit = uunit;
                model.utel = utel;
                model.uprovince = uprovince;
                model.ucity = ucity;
                model.ucounty = ucounty;
                model.uadd = uadd;
                //model.ulevel = ulevel;
                model.utype = utype;
                model.remark = remark;
                model.uid = uid;
                jnpic.BLL.userinfo bll = new jnpic.BLL.userinfo();
                if (bll.Update(model))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();

                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void adda(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int level = Web.Admin.myinfo.getLevel(context);
                if (level == 5)
                {
                    string uname = context.Request.Form["uname"];
                    string upwd = context.Request.Form["upwd"];
                    string utruename = context.Request.Form["utruename"];
                    string uphone = context.Request.Form["uphone"];
                    string uemail = context.Request.Form["uemail"];
                    string uunit = context.Request.Form["uunit"];
                    string utel = context.Request.Form["utel"];
                    string uprovince = context.Request.Form["uprovince"];
                    string ucity = context.Request.Form["ucity"];
                    string ucounty = context.Request.Form["ucounty"];
                    string uadd = context.Request.Form["uadd"];
                    string remark = context.Request.Form["remark"];
                    string slevel = context.Request.Form["ulevel"];
                    int alevel = 0;
                    if (slevel != "")
                        alevel = int.Parse(slevel);
                    jnpic.Model.userinfo model = new jnpic.Model.userinfo();
                    model.uname = uname;
                    model.upwd = upwd;
                    model.utruename = utruename;
                    model.uphone = uphone;
                    model.uemail = uemail;
                    model.uunit = uunit;
                    model.utel = utel;
                    model.uprovince = uprovince;
                    model.ucity = ucity;
                    model.ucounty = ucounty;
                    model.uadd = uadd;
                    model.ulevel = alevel;
                    model.utype = "林";
                    model.remark = remark;
                    model.cuid = Web.Admin.myinfo.getID(context);
                    jnpic.BLL.userinfo bll = new jnpic.BLL.userinfo();
                    int rid = bll.Add(model);
                    if ( rid> 0)
                    {
                        jnpic.BLL.SysUserRole sur = new BLL.SysUserRole();
                        jnpic.Model.SysUserRole rr=new Model.SysUserRole();
                        rr.UserID=rid;
                        rr.RoleID=6-alevel;
                        sur.Add(rr);
                        context.Response.Write("T");//返回给前台页面  
                        context.Response.End();
                    }
                    else
                    {
                        context.Response.Write("F");//返回给前台页面  
                        context.Response.End();
                    }
                }                

            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }  
        public void add(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                string uname = context.Request.Form["uname"];
                string upwd = context.Request.Form["upwd"];
                string utruename = context.Request.Form["utruename"];
                string uphone = context.Request.Form["uphone"];
                string uemail = context.Request.Form["uemail"];
                string uunit = context.Request.Form["uunit"];
                string utel = context.Request.Form["utel"];
                string uprovince = context.Request.Form["uprovince"];
                string ucity = context.Request.Form["ucity"];
                string ucounty = context.Request.Form["ucounty"];
                string uadd = context.Request.Form["uadd"];
                string remark = context.Request.Form["remark"];
                jnpic.Model.userinfo model = new jnpic.Model.userinfo();
                model.uname = uname;
                model.upwd = upwd;
                model.utruename = utruename;
                model.uphone = uphone;
                model.uemail = uemail;
                model.uunit = uunit;
                model.utel = utel;
                model.uprovince = uprovince;
                model.ucity = ucity;
                model.ucounty = ucounty;
                model.uadd = uadd;
                model.ulevel = 0;
                model.utype ="林";
                model.remark = remark;
                model.cuid = Web.Admin.myinfo.getID(context);
                jnpic.BLL.userinfo bll = new jnpic.BLL.userinfo();
                int rid = bll.Add(model);
                if (rid > 0)
                {
                    jnpic.BLL.SysUserRole sur = new BLL.SysUserRole();
                    jnpic.Model.SysUserRole rr = new Model.SysUserRole();
                    rr.UserID = rid;
                    rr.RoleID = 6;
                    sur.Add(rr);
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void myinfo(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                
                DataSet ds = bll.GetList(" uid="+ uid);

                string strJson = ToJson.DataTable2Json2(ds.Tables[0]);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }
        public void Query(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                string uname, utruename, st;
                uname = utruename = st = "";
                //获取前台传来的值 
                if (null != context.Request.Form["search_type"])
                {//获取前台传来的值  
                    st = context.Request.Form["search_type"].ToString().Trim();
                }
                if (null != context.Request.Form["search_value"])
                {//获取前台传来的值  
                    uname = context.Request.Form["search_value"].ToString().Trim();
                }
                if (st == "username")
                {
                    utruename = uname;
                    uname = "";
                }  
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());

                }
                if (null != context.Request.Form["page"])
                {

                    page = int.Parse(context.Request.Form["page"].ToString().Trim());

                }
                if (null != context.Request.Form["sort"])
                {

                    order = context.Request.Form["sort"].ToString().Trim();

                }
                if (null != context.Request.Form["order"])
                {

                    sort = context.Request.Form["order"].ToString().Trim();

                }
                StringBuilder strWhere = new StringBuilder();
                if (uname != "")
                {
                    strWhere.AppendFormat(" uname like '%{0}%' and ", uname);
                }
                if (utruename != "")
                {
                    strWhere.AppendFormat(" utruename like '%{0}%' and ", utruename);
                }

                strWhere.AppendFormat(" cuid={0} and ", uid); 
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    //strWhere.AppendFormat(" order by {0} {1}", sort, order);//添加排序  
                    oderby = order + " " + sort;
                }
                //DataSet ds = Bnotice.GetList(strWhere.ToString());  //调用不分页的getlist  

                //调用分页的GetList方法  
                DataSet ds = bll.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }
        public void Querya(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = Web.Admin.myinfo.getID(context);
                string uname, utruename, st,spro,scity,scou;
                uname = utruename = st =spro=scity=scou="";
                //获取前台传来的值 
                if (null != context.Request.Form["search_type"])
                {//获取前台传来的值  
                    st = context.Request.Form["search_type"].ToString().Trim();
                }
                if (null != context.Request.Form["search_value"])
                {//获取前台传来的值  
                    uname = context.Request.Form["search_value"].ToString().Trim();
                }
                if (st == "username")
                {
                    utruename = uname;
                    uname = "";
                }
                if (null != context.Request.Form["spro"])
                {//获取前台传来的值  
                    spro = context.Request.Form["spro"].ToString().Trim();
                }
                if (null != context.Request.Form["scity"])
                {//获取前台传来的值  
                    scity = context.Request.Form["scity"].ToString().Trim();
                }
                if (null != context.Request.Form["scou"])
                {//获取前台传来的值  
                    scou = context.Request.Form["scou"].ToString().Trim();
                }
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());

                }
                if (null != context.Request.Form["page"])
                {

                    page = int.Parse(context.Request.Form["page"].ToString().Trim());

                }
                if (null != context.Request.Form["sort"])
                {

                    order = context.Request.Form["sort"].ToString().Trim();

                }
                if (null != context.Request.Form["order"])
                {

                    sort = context.Request.Form["order"].ToString().Trim();

                }
                StringBuilder strWhere = new StringBuilder();
                if (uname != "")
                {
                    strWhere.AppendFormat(" uname like '%{0}%' and ", uname);
                }
                if (utruename != "")
                {
                    strWhere.AppendFormat(" utruename like '%{0}%' and ", utruename);
                }
                if (spro != "")
                {
                    strWhere.AppendFormat(" uprovince='{0}' and ",spro);
                }
                if (scity != "")
                {
                    strWhere.AppendFormat(" ucity='{0}' and ", scity);
                }
                if (scou != "")
                {
                    strWhere.AppendFormat(" ucounty='{0}' and ", scou);
                }
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {                    
                    oderby = order + " " + sort;
                }               
                DataSet ds = bll.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }

        }
        public void Querymym(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int level = Web.Admin.myinfo.getLevel(context);
                string uname, utruename, uprovince, ucity, uunit, ucounty, utype = "1";
                utruename = uname = uprovince = ucity = uunit = ucounty = "";

                string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                if (null != context.Request.Form["uname"])
                {
                    uname = context.Request.Form["uname"].ToString().Trim();
                }
                if (null != context.Request.Form["utruename"])
                {
                    utruename = context.Request.Form["utruename"].ToString().Trim();
                }
                if (null != context.Request.Form["uprovince"])
                {
                    uprovince = context.Request.Form["uprovince"].ToString().Trim();
                }
                if (null != context.Request.Form["ucity"])
                {
                    ucity = context.Request.Form["ucity"].ToString().Trim();
                }
                if (null != context.Request.Form["ucounty"])
                {
                    ucounty = context.Request.Form["ucounty"].ToString().Trim();
                }
                if (null != context.Request.Form["utype"])
                {
                    utype = context.Request.Form["utype"].ToString().Trim();
                }
                if (null != context.Request.Form["uunit"])
                {
                    uunit = context.Request.Form["uunit"].ToString().Trim();
                }
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());
                }
                if (null != context.Request.Form["page"])
                {
                    page = int.Parse(context.Request.Form["page"].ToString().Trim());
                }
                if (null != context.Request.Form["sort"])
                {
                    order = context.Request.Form["sort"].ToString().Trim();
                }
                if (null != context.Request.Form["order"])
                {
                    sort = context.Request.Form["order"].ToString().Trim();
                }
                StringBuilder strWhere = new StringBuilder();
                if (uname != "")
                {
                    strWhere.AppendFormat(" uname like '%{0}%' and ", uname);
                }
                if (utruename != "")
                {
                    strWhere.AppendFormat(" utruename like '%{0}%' and ", utruename);
                }
                if (level <= 3)
                    uprovince = pcc[0];
                if (level <= 2)
                {
                    ucity = pcc[1];
                }
                if (level <= 1)
                {
                    ucounty = pcc[2];
                }
                if (ucounty != "")
                {
                    strWhere.AppendFormat(" ucounty='{0}' and ", ucounty);
                }

                if (ucity != "")
                {
                    strWhere.AppendFormat(" ucity='{0}' and ", ucity);
                }

                if (uprovince != "")
                {
                    strWhere.AppendFormat(" uprovince='{0}' and ", uprovince);

                }
                if (utype == "2")
                {
                    strWhere.Append(" ulevel>0 and ");

                }
                else if (utype == "3")
                {
                    strWhere.Append(" ulevel=0 and ");

                }
                if (uunit != "")
                {
                    strWhere.AppendFormat(" uunit like '%{0}%' and ", uunit);

                }
                strWhere.AppendFormat(" ulevel<{0} and ", level);
                //删除多余的and  
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    oderby = order + " " + sort;
                }
                DataSet ds = bll.GetListByPagem(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCountm(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }  
        public void Querymy(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                int level = Web.Admin.myinfo.getLevel(context);
                string uname,utruename, uprovince, ucity, uunit,ucounty,utype="1";
                utruename = uname = uprovince = ucity = uunit=ucounty = "";
                
                string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                if (null != context.Request.Form["uname"])
                {
                    uname = context.Request.Form["uname"].ToString().Trim();
                }
                if (null != context.Request.Form["utruename"])
                {
                    utruename = context.Request.Form["utruename"].ToString().Trim();
                }
                if (null != context.Request.Form["uprovince"])
                {
                    uprovince = context.Request.Form["uprovince"].ToString().Trim();
                }
                if (null != context.Request.Form["ucity"])
                {
                    ucity = context.Request.Form["ucity"].ToString().Trim();
                }
                if (null != context.Request.Form["ucounty"])
                {
                    ucounty = context.Request.Form["ucounty"].ToString().Trim();
                }
                if (null != context.Request.Form["utype"])
                {
                    utype = context.Request.Form["utype"].ToString().Trim();
                }
                if (null != context.Request.Form["uunit"])
                {
                    uunit = context.Request.Form["uunit"].ToString().Trim();
                }
                int pageRows, page;
                pageRows = 10;
                page = 1;
                string order, sort, oderby; order = sort = oderby = "";
                if (null != context.Request.Form["rows"])
                {
                    pageRows = int.Parse(context.Request.Form["rows"].ToString().Trim());
                }
                if (null != context.Request.Form["page"])
                {
                    page = int.Parse(context.Request.Form["page"].ToString().Trim());
                }
                if (null != context.Request.Form["sort"])
                {
                    order = context.Request.Form["sort"].ToString().Trim();
                }
                if (null != context.Request.Form["order"])
                {
                    sort = context.Request.Form["order"].ToString().Trim();
                }
                StringBuilder strWhere = new StringBuilder();
                if (uname != "")
                {
                    strWhere.AppendFormat(" uname like '%{0}%' and ", uname);
                }
                if (utruename != "")
                {
                    strWhere.AppendFormat(" utruename like '%{0}%' and ", utruename);
                }
                if (level <= 3)
                    uprovince = pcc[0];
                if (level <= 2)
                {
                    ucity = pcc[1];
                }
                if (level <= 1)
                {
                    ucounty = pcc[2];
                }
                if (ucounty != "")
                {
                    strWhere.AppendFormat(" ucounty='{0}' and ", ucounty);
                }

                if (ucity != "")
                {
                    strWhere.AppendFormat(" ucity='{0}' and ", ucity);
                }

                if (uprovince != "")
                {
                    strWhere.AppendFormat(" uprovince='{0}' and ", uprovince);

                }
                if (utype == "2")
                {
                    strWhere.Append(" ulevel>0 and ");

                }
                else if (utype == "3")
                {
                    strWhere.Append(" ulevel=0 and ");

                }
                if (uunit != "")
                {
                    strWhere.AppendFormat(" uunit like '%{0}%' and ", uunit);

                }
                strWhere.AppendFormat(" ulevel<{0} and ",level);
                //删除多余的and  
                int startindex = strWhere.ToString().LastIndexOf("and");//获取最后一个and的位置  
                if (startindex >= 0)
                {
                    strWhere.Remove(startindex, 3);//删除多余的and关键字  
                }
                if (sort != "" && order != "")
                {
                    oderby = order + " " + sort;
                }
                DataSet ds = bll.GetListByPage(strWhere.ToString(), oderby, (page - 1) * pageRows + 1, page * pageRows);
                int count = bll.GetRecordCount(strWhere.ToString());//获取条数  
                string strJson = ToJson.Dataset2Json(ds, count);//DataSet数据转化为Json数据  
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }  
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}